package com.itheima.controller.backend.security;

import com.itheima.common.dto.QueryPageBeanDTO;
import com.itheima.common.entity.PageResult;
import com.itheima.common.entity.Result;
import com.itheima.pojo.CheckItem;
import com.itheima.service.CheckItemService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/backend/order")
public class CheckItemController {
    @Autowired
    private CheckItemService orderService;

    /**
     * 新增检查项
     * @param checkItem
     * @return
     */
    @PostMapping("/addCheckitem")
    public Result addCheckitem(@RequestBody CheckItem checkItem) {
        log.info("新增检查项:{}",checkItem);
        orderService.addCheckitem(checkItem);
        return Result.success();
    }

    /**
     * 删除检查项
     * @param id
     * @return
     */
    @DeleteMapping("/deleteCheckitem/{id}")
    public Result deleteCheckitem(@PathVariable Integer id) {
        log.info("删除检查项:{}",id);
        orderService.deleteCheckitem(id);
        return Result.success();
    }

    /**
     * 修改检查项
     * @param checkItem
     * @return
     */
    @PutMapping("/modifyCheckitem")
    public Result modifyCheckitem(@RequestBody CheckItem checkItem) {
        log.info("修改检查项:{}",checkItem);
        orderService.modifyCheckitem(checkItem);
        return Result.success();
    }

    /**
     * 根据检查项id查询对应检查项
     * @return
     */
    @GetMapping("/checkitem")
    public Result getCheckitemById(Integer id) {
        log.info("根据检查项id查询对应检查项：{}",id);
        CheckItem checkItem = orderService.getCheckitemById(id);
        return Result.success(checkItem);
    }

    /**
     * 分页查询检查项
     * @param queryPageBeanDto
     * @return
     */
    @GetMapping("/page")
    public Result pageCheckitem(@RequestBody QueryPageBeanDTO queryPageBeanDto) {
        log.info("分页查询：");
        PageResult pageResult = orderService.pageCheckitem(queryPageBeanDto);
        return Result.success(pageResult);
    }
}
